package com.dapeng.cleardatabackend.common;

import com.dapeng.cleardatabackend.model.entity.User;

/**
 * 登录用户持有者
 *
 * @author zhuodapeng
 * @date 2024/12/05
 */
public class LoginUserHolder {
    public static ThreadLocal<User> threadLocal = new ThreadLocal<>();

    /**
     * 设置登录用户
     *
     * @param loginUser 登录用户
     */
    public static void setLoginUser(User loginUser) {
        threadLocal.set(loginUser);
    }

    /**
     * 获取登录用户
     *
     * @return {@link User }
     */
    public static User getLoginUser() {
        return threadLocal.get();
    }

    /**
     * 清除
     */
    public static void clear() {
        threadLocal.remove();
    }
}